using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Advance;

public class FormSettings : Form
{
	private IContainer components = null;

	private GroupBox groupBox1;

	private GroupBox groupBox2;

	private GroupBox groupBox3;

	private GroupBox groupBox4;

	private RadioButton rbtnHVN3000;

	private RadioButton rbtnHVN2500;

	private GroupBox groupBox5;

	private RadioButton rbtnEMNew;

	private RadioButton rbtnEMOld;

	private RadioButton rbtniMass;

	private RadioButton rbtnICPMS1000;

	private RadioButton rbtnBlackGauge;

	private RadioButton rbtnRedGauge;

	private Button btnSave;

	private GroupBox groupBox6;

	private RadioButton rbtnDetectorOld;

	private RadioButton rbtnDetectorNew;

	private RadioButton rbtnBlueGauge;

	private GroupBox groupBox7;

	private RadioButton rbtnOneWay;

	private RadioButton rbtnTwoWay;

	public FormSettings()
	{
		InitializeComponent();
	}

	private void FormSettings_Load(object sender, EventArgs e)
	{
		rbtnEMNew.Checked = Detector.detectorConfig.IsNewBoard;
		rbtnEMOld.Checked = !rbtnEMNew.Checked;
		rbtnHVN2500.Checked = Detector.detectorConfig.RangeHVN == 2500.0;
		rbtnHVN3000.Checked = !rbtnHVN2500.Checked;
		rbtnDetectorNew.Checked = (Detector.detectorConfig.IsNewDetector ? true : false);
		rbtnDetectorOld.Checked = !rbtnDetectorNew.Checked;
		rbtnOneWay.Checked = Collision.Instance.CRCType == 1;
		rbtnTwoWay.Checked = !rbtnOneWay.Checked;
		InstrumentType instrumentType = new InstrumentType();
		string path = "//iMassConfig//InstrumentType.txt";
		try
		{
			using StreamReader sr = File.OpenText(Application.StartupPath + path);
			instrumentType.InstruType = int.Parse(sr.ReadLine());
		}
		catch (Exception)
		{
			instrumentType.InstruType = 0;
		}
		if (Vacuum.Instance.VacuumType == 1)
		{
			rbtnRedGauge.Checked = true;
			rbtnBlackGauge.Checked = false;
			rbtnBlueGauge.Checked = false;
		}
		else if (Vacuum.Instance.VacuumType == 2)
		{
			rbtnBlackGauge.Checked = true;
			rbtnRedGauge.Checked = false;
			rbtnBlueGauge.Checked = false;
		}
		else if (Vacuum.Instance.VacuumType == 3)
		{
			rbtnBlueGauge.Checked = true;
			rbtnRedGauge.Checked = false;
			rbtnBlackGauge.Checked = false;
		}
		else
		{
			rbtnBlackGauge.Checked = true;
			rbtnRedGauge.Checked = false;
			rbtnBlueGauge.Checked = false;
		}
		ApplyResources();
	}

	private void btnSave_Click(object sender, EventArgs e)
	{
		Detector.detectorConfig.IsNewBoard = rbtnEMNew.Checked;
		Detector.detectorConfig.RangeHVN = (rbtnHVN2500.Checked ? 2500 : 3000);
		Detector.detectorConfig.IsNewDetector = (rbtnDetectorNew.Checked ? true : false);
		InstrumentType instrumentType = new InstrumentType();
		instrumentType.InstruType = ((!rbtniMass.Checked) ? 1 : 0);
		Collision.Instance.CRCType = (rbtnOneWay.Checked ? 1 : 2);
		string path = "//iMassConfig//InstrumentType.txt";
		try
		{
			using FileStream fs = File.Create(Application.StartupPath + path);
			using StreamWriter sr = new StreamWriter(fs);
			sr.WriteLine(instrumentType.InstruType);
			sr.Close();
		}
		catch (Exception ex)
		{
			Log.InsertLog("仪器配置", "保存失败", ex.Message, (Severity)3);
		}
		if (rbtnRedGauge.Checked)
		{
			Vacuum.Instance.VacuumType = 1;
		}
		else if (rbtnBlackGauge.Checked)
		{
			Vacuum.Instance.VacuumType = 2;
		}
		else if (rbtnBlueGauge.Checked)
		{
			Vacuum.Instance.VacuumType = 3;
		}
		else
		{
			Vacuum.Instance.VacuumType = 2;
		}
	}

	private void ApplyResources()
	{
		groupBox1.Text = Lang.Txt("AddFormSettings.MultiplierConfiguration");
		groupBox2.Text = Lang.Txt("AddFormSettings.MFCConfiguration");
		groupBox3.Text = Lang.Txt("AddFormSettings.VacuumConfiguration");
		groupBox5.Text = Lang.Txt("AddFormSettings.ModelNumber");
		rbtnEMOld.Text = Lang.Txt("AddFormSettings.OldMultiplier");
		rbtnEMNew.Text = Lang.Txt("AddFormSettings.NewMultiplier");
		groupBox4.Text = Lang.Txt("AddFormSettings.HVNRange");
		rbtnBlackGauge.Text = Lang.Txt("AddFormSettings.BlackPenning");
		rbtnRedGauge.Text = Lang.Txt("AddFormSettings.RedPenning");
		groupBox6.Text = Lang.Txt("AddFormSettings.DetectorConfiguration");
		rbtnDetectorOld.Text = Lang.Txt("AddFormSettings.OrdinaryDetector");
		rbtnDetectorNew.Text = Lang.Txt("AddFormSettings.SplitDetector");
		rbtnBlueGauge.Text = Lang.Txt("AddFormSettings.rbtnBlueGauge");
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.groupBox4 = new System.Windows.Forms.GroupBox();
		this.rbtnHVN3000 = new System.Windows.Forms.RadioButton();
		this.rbtnHVN2500 = new System.Windows.Forms.RadioButton();
		this.groupBox5 = new System.Windows.Forms.GroupBox();
		this.rbtnEMNew = new System.Windows.Forms.RadioButton();
		this.rbtnEMOld = new System.Windows.Forms.RadioButton();
		this.groupBox2 = new System.Windows.Forms.GroupBox();
		this.rbtniMass = new System.Windows.Forms.RadioButton();
		this.rbtnICPMS1000 = new System.Windows.Forms.RadioButton();
		this.groupBox3 = new System.Windows.Forms.GroupBox();
		this.rbtnBlueGauge = new System.Windows.Forms.RadioButton();
		this.rbtnBlackGauge = new System.Windows.Forms.RadioButton();
		this.rbtnRedGauge = new System.Windows.Forms.RadioButton();
		this.btnSave = new System.Windows.Forms.Button();
		this.groupBox6 = new System.Windows.Forms.GroupBox();
		this.rbtnDetectorOld = new System.Windows.Forms.RadioButton();
		this.rbtnDetectorNew = new System.Windows.Forms.RadioButton();
		this.groupBox7 = new System.Windows.Forms.GroupBox();
		this.rbtnOneWay = new System.Windows.Forms.RadioButton();
		this.rbtnTwoWay = new System.Windows.Forms.RadioButton();
		this.groupBox1.SuspendLayout();
		this.groupBox4.SuspendLayout();
		this.groupBox5.SuspendLayout();
		this.groupBox2.SuspendLayout();
		this.groupBox3.SuspendLayout();
		this.groupBox6.SuspendLayout();
		this.groupBox7.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Controls.Add(this.groupBox4);
		this.groupBox1.Controls.Add(this.groupBox5);
		this.groupBox1.Location = new System.Drawing.Point(12, 12);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(763, 216);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "倍增器配置";
		this.groupBox4.Controls.Add(this.rbtnHVN3000);
		this.groupBox4.Controls.Add(this.rbtnHVN2500);
		this.groupBox4.Location = new System.Drawing.Point(21, 116);
		this.groupBox4.Name = "groupBox4";
		this.groupBox4.Size = new System.Drawing.Size(716, 74);
		this.groupBox4.TabIndex = 1;
		this.groupBox4.TabStop = false;
		this.groupBox4.Text = "负高压范围";
		this.rbtnHVN3000.AutoSize = true;
		this.rbtnHVN3000.Checked = true;
		this.rbtnHVN3000.Location = new System.Drawing.Point(317, 36);
		this.rbtnHVN3000.Name = "rbtnHVN3000";
		this.rbtnHVN3000.Size = new System.Drawing.Size(60, 19);
		this.rbtnHVN3000.TabIndex = 1;
		this.rbtnHVN3000.TabStop = true;
		this.rbtnHVN3000.Text = "3000";
		this.rbtnHVN3000.UseVisualStyleBackColor = true;
		this.rbtnHVN2500.AutoSize = true;
		this.rbtnHVN2500.Location = new System.Drawing.Point(33, 36);
		this.rbtnHVN2500.Name = "rbtnHVN2500";
		this.rbtnHVN2500.Size = new System.Drawing.Size(60, 19);
		this.rbtnHVN2500.TabIndex = 1;
		this.rbtnHVN2500.Text = "2500";
		this.rbtnHVN2500.UseVisualStyleBackColor = true;
		this.groupBox5.Controls.Add(this.rbtnEMNew);
		this.groupBox5.Controls.Add(this.rbtnEMOld);
		this.groupBox5.Location = new System.Drawing.Point(21, 37);
		this.groupBox5.Name = "groupBox5";
		this.groupBox5.Size = new System.Drawing.Size(716, 74);
		this.groupBox5.TabIndex = 2;
		this.groupBox5.TabStop = false;
		this.groupBox5.Text = "型号";
		this.rbtnEMNew.AutoSize = true;
		this.rbtnEMNew.Checked = true;
		this.rbtnEMNew.Location = new System.Drawing.Point(315, 36);
		this.rbtnEMNew.Name = "rbtnEMNew";
		this.rbtnEMNew.Size = new System.Drawing.Size(88, 19);
		this.rbtnEMNew.TabIndex = 1;
		this.rbtnEMNew.TabStop = true;
		this.rbtnEMNew.Text = "新倍增器";
		this.rbtnEMNew.UseVisualStyleBackColor = true;
		this.rbtnEMOld.AutoSize = true;
		this.rbtnEMOld.Location = new System.Drawing.Point(33, 36);
		this.rbtnEMOld.Name = "rbtnEMOld";
		this.rbtnEMOld.Size = new System.Drawing.Size(88, 19);
		this.rbtnEMOld.TabIndex = 1;
		this.rbtnEMOld.Text = "老倍增器";
		this.rbtnEMOld.UseVisualStyleBackColor = true;
		this.groupBox2.Controls.Add(this.rbtniMass);
		this.groupBox2.Controls.Add(this.rbtnICPMS1000);
		this.groupBox2.Location = new System.Drawing.Point(12, 508);
		this.groupBox2.Name = "groupBox2";
		this.groupBox2.Size = new System.Drawing.Size(471, 70);
		this.groupBox2.TabIndex = 0;
		this.groupBox2.TabStop = false;
		this.groupBox2.Text = "MFC配置";
		this.groupBox2.Visible = false;
		this.rbtniMass.AutoSize = true;
		this.rbtniMass.Checked = true;
		this.rbtniMass.Location = new System.Drawing.Point(338, 36);
		this.rbtniMass.Name = "rbtniMass";
		this.rbtniMass.Size = new System.Drawing.Size(132, 19);
		this.rbtniMass.TabIndex = 2;
		this.rbtniMass.TabStop = true;
		this.rbtniMass.Text = "iMass 300/400";
		this.rbtniMass.UseVisualStyleBackColor = true;
		this.rbtnICPMS1000.AutoSize = true;
		this.rbtnICPMS1000.Location = new System.Drawing.Point(54, 36);
		this.rbtnICPMS1000.Name = "rbtnICPMS1000";
		this.rbtnICPMS1000.Size = new System.Drawing.Size(116, 19);
		this.rbtnICPMS1000.TabIndex = 3;
		this.rbtnICPMS1000.Text = "ICP-MS 1000";
		this.rbtnICPMS1000.UseVisualStyleBackColor = true;
		this.groupBox3.Controls.Add(this.rbtnBlueGauge);
		this.groupBox3.Controls.Add(this.rbtnBlackGauge);
		this.groupBox3.Controls.Add(this.rbtnRedGauge);
		this.groupBox3.Location = new System.Drawing.Point(12, 239);
		this.groupBox3.Name = "groupBox3";
		this.groupBox3.Size = new System.Drawing.Size(763, 69);
		this.groupBox3.TabIndex = 0;
		this.groupBox3.TabStop = false;
		this.groupBox3.Text = "真空规配置";
		this.rbtnBlueGauge.AutoSize = true;
		this.rbtnBlueGauge.Location = new System.Drawing.Point(582, 31);
		this.rbtnBlueGauge.Name = "rbtnBlueGauge";
		this.rbtnBlueGauge.Size = new System.Drawing.Size(58, 19);
		this.rbtnBlueGauge.TabIndex = 4;
		this.rbtnBlueGauge.Text = "蓝规";
		this.rbtnBlueGauge.UseVisualStyleBackColor = true;
		this.rbtnBlackGauge.AutoSize = true;
		this.rbtnBlackGauge.Location = new System.Drawing.Point(54, 31);
		this.rbtnBlackGauge.Name = "rbtnBlackGauge";
		this.rbtnBlackGauge.Size = new System.Drawing.Size(58, 19);
		this.rbtnBlackGauge.TabIndex = 2;
		this.rbtnBlackGauge.Text = "黑规";
		this.rbtnBlackGauge.UseVisualStyleBackColor = true;
		this.rbtnRedGauge.AutoSize = true;
		this.rbtnRedGauge.Checked = true;
		this.rbtnRedGauge.Location = new System.Drawing.Point(338, 31);
		this.rbtnRedGauge.Name = "rbtnRedGauge";
		this.rbtnRedGauge.Size = new System.Drawing.Size(58, 19);
		this.rbtnRedGauge.TabIndex = 3;
		this.rbtnRedGauge.TabStop = true;
		this.rbtnRedGauge.Text = "红规";
		this.rbtnRedGauge.UseVisualStyleBackColor = true;
		this.btnSave.Location = new System.Drawing.Point(577, 549);
		this.btnSave.Name = "btnSave";
		this.btnSave.Size = new System.Drawing.Size(172, 29);
		this.btnSave.TabIndex = 2;
		this.btnSave.Text = "保存";
		this.btnSave.UseVisualStyleBackColor = true;
		this.btnSave.Click += new System.EventHandler(btnSave_Click);
		this.groupBox6.Controls.Add(this.rbtnDetectorOld);
		this.groupBox6.Controls.Add(this.rbtnDetectorNew);
		this.groupBox6.Location = new System.Drawing.Point(12, 329);
		this.groupBox6.Name = "groupBox6";
		this.groupBox6.Size = new System.Drawing.Size(763, 69);
		this.groupBox6.TabIndex = 3;
		this.groupBox6.TabStop = false;
		this.groupBox6.Text = "采集板配置";
		this.rbtnDetectorOld.AutoSize = true;
		this.rbtnDetectorOld.Checked = true;
		this.rbtnDetectorOld.Location = new System.Drawing.Point(54, 31);
		this.rbtnDetectorOld.Name = "rbtnDetectorOld";
		this.rbtnDetectorOld.Size = new System.Drawing.Size(103, 19);
		this.rbtnDetectorOld.TabIndex = 2;
		this.rbtnDetectorOld.TabStop = true;
		this.rbtnDetectorOld.Text = "普通采集板";
		this.rbtnDetectorOld.UseVisualStyleBackColor = true;
		this.rbtnDetectorNew.AutoSize = true;
		this.rbtnDetectorNew.Location = new System.Drawing.Point(338, 31);
		this.rbtnDetectorNew.Name = "rbtnDetectorNew";
		this.rbtnDetectorNew.Size = new System.Drawing.Size(118, 19);
		this.rbtnDetectorNew.TabIndex = 3;
		this.rbtnDetectorNew.Text = "分体式采集板";
		this.rbtnDetectorNew.UseVisualStyleBackColor = true;
		this.groupBox7.Controls.Add(this.rbtnOneWay);
		this.groupBox7.Controls.Add(this.rbtnTwoWay);
		this.groupBox7.Location = new System.Drawing.Point(12, 420);
		this.groupBox7.Name = "groupBox7";
		this.groupBox7.Size = new System.Drawing.Size(763, 69);
		this.groupBox7.TabIndex = 4;
		this.groupBox7.TabStop = false;
		this.groupBox7.Text = "MFC配置";
		this.rbtnOneWay.AutoSize = true;
		this.rbtnOneWay.Checked = true;
		this.rbtnOneWay.Location = new System.Drawing.Point(54, 31);
		this.rbtnOneWay.Name = "rbtnOneWay";
		this.rbtnOneWay.Size = new System.Drawing.Size(58, 19);
		this.rbtnOneWay.TabIndex = 2;
		this.rbtnOneWay.TabStop = true;
		this.rbtnOneWay.Text = "单路";
		this.rbtnOneWay.UseVisualStyleBackColor = true;
		this.rbtnTwoWay.AutoSize = true;
		this.rbtnTwoWay.Location = new System.Drawing.Point(338, 31);
		this.rbtnTwoWay.Name = "rbtnTwoWay";
		this.rbtnTwoWay.Size = new System.Drawing.Size(58, 19);
		this.rbtnTwoWay.TabIndex = 3;
		this.rbtnTwoWay.Text = "双路";
		this.rbtnTwoWay.UseVisualStyleBackColor = true;
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(846, 622);
		base.Controls.Add(this.groupBox7);
		base.Controls.Add(this.groupBox6);
		base.Controls.Add(this.btnSave);
		base.Controls.Add(this.groupBox3);
		base.Controls.Add(this.groupBox2);
		base.Controls.Add(this.groupBox1);
		base.Name = "FormSettings";
		this.Text = "硬件配置";
		base.Load += new System.EventHandler(FormSettings_Load);
		this.groupBox1.ResumeLayout(false);
		this.groupBox4.ResumeLayout(false);
		this.groupBox4.PerformLayout();
		this.groupBox5.ResumeLayout(false);
		this.groupBox5.PerformLayout();
		this.groupBox2.ResumeLayout(false);
		this.groupBox2.PerformLayout();
		this.groupBox3.ResumeLayout(false);
		this.groupBox3.PerformLayout();
		this.groupBox6.ResumeLayout(false);
		this.groupBox6.PerformLayout();
		this.groupBox7.ResumeLayout(false);
		this.groupBox7.PerformLayout();
		base.ResumeLayout(false);
	}
}
